package com.lc.afbx.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiConfirmXuBao;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/6/22.
 */
public class XuBaoAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<GetApiConfirmXuBao.Data> dataList;
    public HashMap<Integer, Integer> colorMap;


    public XuBaoAdapter(Context context, List<GetApiConfirmXuBao.Data> dataList) {
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.dataList = dataList;

        colorMap = new HashMap<>();
        for (int i = 0; i < dataList.size(); i++) {
            colorMap.put(i, context.getResources().getColor(R.color.white));
        }
    }

    public void init() {
        for (int i = 0; i < dataList.size(); i++) {
            colorMap.put(i, context.getResources().getColor(R.color.white));
        }
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view = null;
        ViewHolder holder = null;

        if (view == null) {
            view = inflater.inflate(R.layout.item_xubao, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) view);
            holder = new ViewHolder();

            holder.conpany = (TextView) view.findViewById(R.id.conpany);//公司
            holder.plateNum = (TextView) view.findViewById(R.id.plate_number);//车牌号
            holder.vin = (TextView) view.findViewById(R.id.vin);//车架号

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        String str = "该车牌曾在" + dataList.get(position).company + "投保过，请确认本次投保车辆：";
        holder.conpany.setText(str);
        holder.plateNum.setText(dataList.get(position).plate_number);
        holder.vin.setText(dataList.get(position).vin);

        view.setBackgroundColor(colorMap.get(position));

        return view;
    }

    class ViewHolder {
        TextView conpany, plateNum, vin;

    }
}
